//package com.douqu.game.battle.server.job;
//
//import com.bean.core.util.TimeUtils;
//import com.douqu.game.battle.controller.BattleController;
//import com.douqu.game.battle.controller.sprite.PlayerController;
//import com.douqu.game.battle.server.GameServer;
//import com.douqu.game.battle.server.BattleGroup;
//import com.douqu.game.battle.server.WorldManager;
//import com.douqu.game.core.e.E_PlayerStatus;
//import com.douqu.game.core.factory.ConstantFactory;
//import com.douqu.game.core.factory.DataFactory;
//import com.douqu.game.core.util.LogUtils;
//
//import java.rmi.RemoteException;
//import java.util.List;
//import java.util.concurrent.CopyOnWriteArrayList;
//
///**
// * @Author: Bean
// * @Description:
// * @Date: 2018-01-11 15:21
// */
//public class UpdateBattleJob extends Thread {
//
//    /**
//     * 战斗分组
//     */
//    private int group;
//
//
//    public UpdateBattleJob(int group)
//    {
//        this.group = group;
//        this.setName("UpdateBattleJob group:" + group);
//    }
//
//    @Override
//    public void run()
//    {
//        LogUtils.info("开始新线程......................." + group);
//        BattleGroup battleGroup = GameServer.getInstance().getWorldManager().getGroupBattle(group);
//        if(battleGroup == null)
//            return;
//        List<BattleController> battleControllerList = battleGroup.getBattleControllerList();
//        WorldManager worldManager = GameServer.getInstance().getWorldManager();
//        while(GameServer.getInstance().isRunning())
//        {
//            TimeUtils.sleep(ConstantFactory.UPDATE_BATTLE_TIME);
//
//            List<String> removePlayerIndexs = new CopyOnWriteArrayList<>();
//
//            for(BattleController battleController : battleControllerList)
//            {
//                if(battleController.isOverdue())
//                {
//                    removePlayerIndexs.add(battleController.getSource().getObjectIndex());
//                    if(battleController.getTarget() instanceof PlayerController)
//                        removePlayerIndexs.add(battleController.getTarget().getObjectIndex());
//
//                    worldManager.removeBattleController(battleController);
//                }
//                else
//                    battleController.update(DataFactory.currentTime);
//            }
//
//            if(removePlayerIndexs.size() > 0)
//            {
//                GameServer.getInstance().startThread(() -> {
//                    try {
//                        GameServer.getInstance().getiMainServer().updateStatusByPlayers(
//                                GameServer.getInstance().getId(), E_PlayerStatus.FREE.name(), removePlayerIndexs);
//                    } catch (RemoteException e) {
//                        e.printStackTrace();
//                    }
//                });
//            }
//            if(battleControllerList.size() == 0)
//                break;
//        }
//    }
//}
